package com.msgqu.share.config;

import com.msgqu.share.domain.pub.SnowflakeId;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: wsj
 * @create: 2020-11-12 15:53
 * @throws:
 */
@Component
@Configuration
public class IdGeneratorConfig {

    @Value("${worker.id}")
    private Long workerId;
    @Value("${datacenter.id}")
    private Long datacenterId;

    /**获取生成id算法类 不同的服务workerId和datacenterId一定不能相同*/
    @Bean
    public SnowflakeId idGenerator(){
        SnowflakeId snowflakeId = new SnowflakeId(workerId,datacenterId);
        return snowflakeId;
    }

}
